home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
VideoToolbox 96.06.15
/
(Utilities)
/
GrabDrivers
/
GrabVideoDrivers.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-27
|
7KB
|
201 lines
/*
GrabVideoDrivers.c
Gets each active video driver and saves it in a file of the same name, using the
driver's version number as a resource id. These files can later be examined in
ResEdit, using the public domain CODE editor. You'll want to consult Apple's
Designing Cards and Drivers, 3rd Ed., Addison Wesley.
The ResEdit CODE editor is a public domain file, for use with ResEdit,
distributed by:
Ira L. Ruben
Apple Computer, Inc.
20525 Mariani Ave., MS: 37-A
Cupertino, Ca. 95014
Ira@Apple.Com
ftp://ftp.apple.com/dts/mac/tools/resedit/
Copyright restrictions prevent us from distributing video drivers themselves,
but this program makes it easy for you to get an accessible copy of all the
video drivers used in your own computers.
The primary users of this program will probably be those who wish to enhance
SetEntriesQuickly.c. I hope that people will share the fruits of their labors by
sending me the enhancements for distribution as part of the VideoToolbox.
This program is also useful for copying the Mac IIsi video driver to the Mac
IIci. Since that's a ROM-based driver I don't know any way to automatically
determine its size, and instead this program uses a generous guess. Consequently
the resulting resource is larger than it needs to be. When you install this
resource in the System file of your Mac IIci the excess space is wasted (both on
disk and in memory), but the excess is only about 1 kB, so it doesn't seem worth
worrying about.
HISTORY:
2/89 dgp Wrote it as "video hacker II.c" using THINK "Light Speed" C 3.
12/30/92 dgp updated it to THINK C 5 and renamed it GrabVideoDrivers.c
7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
Metrowerks CodeWarrior C.
9/5/94 dgp removed assumption in printf's that int==short.
6/8/95 dgp Made sure that Mac structs are always 68k aligned.
*/
#include "VideoToolbox.h"
//#include <Errors.h>
//#include <Files.h>
//#include <Resources.h>
Handle GetDriverFromSlotManager(GDHandle device);
void main(void);
void CopyDeviceDriver(GDHandle device);
void AddResourceToFile(unsigned char *filename,unsigned char *name,ResType type
,int id,Handle handle);
#if UNIVERSAL_HEADERS<2
enum{dRAMBasedMask=0x0040}; /* dCtlDriver is a handle (1) or pointer (0) */
#endif
#if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
#pragma options align=mac68k
#endif
typedef struct {
short flags;
short blanks[3];
short open;
short prime;
short control;
short status;
short close;
Str255 name;
} VideoDriver;
VideoDriver *GDDriverAddress(GDHandle device);
#if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
#pragma options align=reset
#endif
void main()
{
GDHandle device;
int i;
MaximizeConsoleHeight();
printf("Welcome to GrabVideoDriver.\n");
printf(BreakLines("This program cycles through all your video devices and copies "
"each driver into a resource file, suitable for subsequent examination "
"with ResEdit (with the CODE editor). This is primarily of interest for people "
"who want to enhance SetEntriesQuickly.c to support more video devices.\n",78));
for(i=0;i<10;i++){
device=GetScreenDevice(i);
if(device==NULL)break;
CopyDeviceDriver(device);
}
printf("\nDone.\n");
}
void CopyDeviceDriver(GDHandle device)
{
char *name,filename[32];
long driverSize;
AuxDCE **auxDCEHandle;
Handle handle;
VideoDriver *driver;
unsigned char *bytePtr;
int version;
if(device==NULL)return;
printf("\n");
name=GDNameStr(device);
version=GDVersion(device);
printf("%s version %d.\n",name,version);
strncpy(filename,name,31);
// filename must be truncated to 31 characters */
filename[32]=0;
// Replace leading "." by "-" since the Mac filing system
// is confused by filenames beginning with ".".
if(filename[0]=='.')filename[0]='-';
driver=GDDriverAddress(device);
printf("Offsets: open 0x%x, prime 0x%x, control 0x%x, status 0x%x, close 0x%x\n"
,driver->open,driver->prime,driver->control,driver->status,driver->close);
printf("name is at 0x%lx, ",driver->name-(unsigned char *) driver);
bytePtr=driver->name;
bytePtr += 1+bytePtr[0]; /* go to end of Pascal string */
bytePtr = (unsigned char *)((long)(bytePtr+1) & ~1); // round up to word boundary
printf("version is at 0x%lx\n",bytePtr-(unsigned char *) driver);
auxDCEHandle = (AuxDCE **) GetDCtlEntry((*device)->gdRefNum);
if((**auxDCEHandle).dCtlFlags & dRAMBasedMask){
printf("RAM-based driver.\n");
handle=(Handle)(**auxDCEHandle).dCtlDriver;
HandToHand(&handle);
printf("%ld bytes\n",GetHandleSize(handle));
}
else{
printf("ROM-based driver.\n");
handle=GetDriverFromSlotManager(device);
if(handle!=NULL){
printf("Got driver with help from Slot Manager.\n");
printf("%ld bytes\n",GetHandleSize(handle));
}else{
// We have a Ptr to the driver, but we don't know how big it is.
driverSize=(unsigned long) GetPtrSize((Ptr)(**auxDCEHandle).dCtlDriver);
if(driverSize==0 || MemError()){
driverSize=driver->open;
if(driverSize<driver->prime)driverSize=driver->prime;
if(driverSize<driver->control)driverSize=driver->control;
if(driverSize<driver->status)driverSize=driver->status;
if(driverSize<driver->close)driverSize=driver->close;
driverSize*=2;
printf("Size unknown, guessing (generously) at %ld, twice the highest offset.\n",driverSize);
}else printf("%ld bytes\n",driverSize);
PtrToHand((**auxDCEHandle).dCtlDriver,&handle,driverSize);
}
}
if(handle!=NULL){
AddResourceToFile(c2pstr(filename),c2pstr(name),'DRVR',version,handle);
printf("Driver copied to “%s” file, using the version number %d as the resource id.\n"
,p2cstr((unsigned char *)filename),version);
DisposHandle(handle);
}else printf("Couldn't copy driver.\n");
}
/*
This gets a copy of the driver from the slot manager. Returns NULL unless we can
find exactly the same driver as is specified by the supplied GDHandle. We check
every byte. This is not a useless operation, because although we already have
the address of the driver, we don't necessarily already have its size, and the
slot manager will supply us with a handle, from which we can obtain the size.
*/
Handle GetDriverFromSlotManager(GDHandle device)
{
SpBlock spBlock;
SEBlock sEBlock;
unsigned char *desiredName,name[256];
int error;
Ptr *handle;
desiredName=GDName(device);
spBlock.spsExecPBlk = (Ptr) &sEBlock;
spBlock.spSlot = 0;
spBlock.spID = 0;
spBlock.spExtDev = 0;
while(1){
error = SNextSRsrc(&spBlock);
if(error==smNoMoresRsrcs) break;
if(error){
printf("SNextSRsrc error %d\n",error);
break;
}
spBlock.spResult = (unsigned long) &name;
error = SReadDrvrName(&spBlock);
if(!EqualString(desiredName,name,1,1))continue;
error = SGetDriver(&spBlock);
if(!error)continue;
handle = (Handle) spBlock.spResult;
if(memcmp(*handle,GDDriverAddress(device),GetHandleSize(handle))!=0){
DisposHandle(handle);
break;
}
return handle;
}
return NULL;
}